let toggleSwitch = document.getElementById('theme-switch');
let htmlDocument = document.documentElement

function vail_function() {
    if (typeof chart_init === "function") {
        chart_init(); chart_data_init();
    }
}

function switchTheme() {
    function setTheme(t) {
        htmlDocument.setAttribute("data-theme", t);
    }

    if (toggleSwitch.checked) {
        setTheme("dark")
        localStorage.setItem("theme", "dark");
        vail_function();
    } else {
        setTheme("light")
        localStorage.setItem("theme", "light");
        vail_function();
    }
}

toggleSwitch.addEventListener('click', function (e) {
    switchTheme()
    vail_function()
});

function configTheme() {
    let local_theme = localStorage.getItem('theme') || "light";
    if (local_theme === "dark") {
        toggleSwitch.checked = true;
        vail_function()
    } else {
        toggleSwitch.checked = false;
        vail_function()
    }
}